<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/11
 * Time: 9:55
 */
require('../vendor/autoload.php');
require('../define.php');
require('util/WechatPlatform.php');

use EasyWeChat\OpenPlatform\Server\Guard;
use \wechat\util\WechatPlatform;

$app = WechatPlatform::getOpenPlatformInstance();
$server = $app->server;
$authCode = $_REQUEST['auth_code'];

$account_info = $app->handleAuthorize($authCode);
$auth_app_id = $account_info["authorization_info"]["authorizer_appid"];
$app['cache']->set('account_info', $account_info, 720000); //-1代表永不过期

$auth_account_info = $app->getAuthorizer($auth_app_id);
$app['cache']->set('auth_account_info', $auth_account_info, 720000);

exit('success');
//TBD save to db